<%- include fheader.ejs%>
<style>
    body{backround-color:#efefef}
   .ui-dialog-bd div{
        text-align: left;
   }
   #qrcodeWrap{
        width: 150px;
        margin: 0 auto;
        padding: 10px;
        border: 1px solid #ccc;
   }
   #qrcodeWrap img{
        width:130px;
        display: block;
   }
   #dlcode img{
        width: 250px;
        display: block;
        margin: 0 auto
   }
   .wrp{
       width:80%;
       background: #fff;
       box-shadow: 1px 1px 1px rgba(0,0,0,.1);
       margin:30px auto;
       position: relative;
       border-radius: 5px;
       padding-bottom: 15px;
   }
   img{
        vertical-align: middle;
   }
    #btnPay{
        width: 80%;
        margin: 0 auto;
        background-color: #18b4ed!important;
        color: white!important;
        height: 40px;
        border-radius: 5px;
    }
    #notice{
        width: 76%;
        margin: 10px auto;
        font-size:12px;

    }

</style>
<% if(orderInfo.pay_type==2){%>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    $(function() {
        var payConfig = {
            //debug:true,
            appId: '<%= payParam.appId%>',
            nonceStr: '<%= payParam.nonceStr%>',
            package: '<%= payParam.package%>',
            paySign: '<%= payParam.paySign%>',
            timeStamp: '<%= payParam.timeStamp%>',
            signType: '<%= payParam.signType%>'
        };

        function onBridgeReady(){
            WeixinJSBridge.invoke("getBrandWCPayRequest", payConfig,function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok") {
                    juq.showTipSuc('支付成功');
                    history.replaceState(200, '','/rest/svcWxPage/operorder');
                    setTimeout(function(){location.href = '/wx/html/paySuccess.html';},100);
                }else{
                    juq.showTipErr('支付失败');
                    //location.href = '/wx/html/payFail.html';
                }
            });
        }
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
                document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    });
</script>

<%}else{%>
     <header class="ui-header ui-header-stable ui-border-b ui-txt-white" style="background:#000">
            <h1>扫码支付</h1>
     </header>
     <section class="ui-container">
         <div class="wrp">
            <div class="ui-panel ui-border-b">
                <h1 style="display:block;color:#00a5e0;text-align:center;">向客户出示二维码付款</h1>
            </div>
            <p style="text-align: center;height: 40px;line-height: 40px;font-size:14px">需支付：<span style="font-size:18px;padding-left:5px">¥<%= orderInfo['order_fee']/100%></span></p>
            <div id="qrcodeWrap"></div>
            <div style="text-align: center; height:40px;line-height: 40px;font-size: 14px;"><img src="/wx/img/wxpay.png" style="width: 22px;height: auto;margin-right: 8px;">微信支付</div>
         </div>
         <a class="ui-btn ui-btn-primary ui-btn-lg" href="javascript:void(0);" id="btnOpPay">
               店员代付
         </a>
         <p class="ui-txt-default" id="notice" style="font-size:12px">
             当客户无法完成线上支付时，可以帮助客户代付完成，请不要忘了向客户收取你所代付的费用哦!</p>
     </section>
    <script src="//cdn.juqingdata.com/assets/js/qrcode.min.js"></script>
    <script>
        $(function(){
            var CHECK_ORDER = '/rest/svcWx/checkOrder';
            var USE_OPPAY = '/rest/svcWx/useOpPay';
            var VTIME = 7200000;//二维码2小时内有效
            var PTIME = 5000;   //轮询订单状态间隔秒
            var sTime = 5000;  //第一次查询间隔秒
            var isQuery = false;
            new QRCode('qrcodeWrap', {text:'<%= payParam['code_url']%>',width:150,height:150});

            $('#btnOpPay').on('touchend',function(){
                juq.fpost(USE_OPPAY, {orderNo:'<%= orderInfo['order_no']%>'},function (res) {
                    location.href = '/rest/svcWxPage/wxpay?orderNo='+res.order_no;
                },function (code, info) {
                    juq.showTipErr(info);
                })
            });

            function checkOrder(){
                sTime += PTIME;
                if(isQuery || sTime>VTIME){
                    return;
                }
                isQuery = true;
                juq.fget(CHECK_ORDER,{orderNo:'<%= orderInfo['order_no']%>'},function(res) {
                    if(res.card_id){
                        juq.showTipSuc('支付成功');
                        history.replaceState(200, '','/rest/svcWxPage/operorder');
                        setTimeout(function(){location.href = '/wx/html/paySuccess.html';},100);
                    }else{
                        isQuery = false;
                        setTimeout(function(){checkOrder()},PTIME);
                    }
                },function(res, info){
                    juq.showTipErr(info);
                });
            }
            setTimeout(function(){checkOrder()},sTime);
        });
    </script>
<%}%>
<%- include ftailer.ejs%>












